
uniform vec2 lpos;

varying vec2 delta;

void main()
{

	vec4 lp = ((vec4(lpos,20,1)));

	vec4 v =    gl_ModelViewProjectionMatrixInverse * ftransform();
	delta = lp.xy-v.xy;

	gl_FrontColor = gl_Color;
	gl_Position = ftransform();
	gl_TexCoord[0] = gl_MultiTexCoord0;
}

FRAGMENT
uniform sampler2D bumpmap;
uniform float r;
uniform float g;
uniform float b;
uniform float a;
uniform float radius;
uniform float ca;
uniform float sa;


varying vec2 delta;


void main()
{
	float alpha = texture2D(bumpmap,gl_TexCoord[0].st).a;
	if(alpha > 0.1){
		vec2 n = texture2D(bumpmap,gl_TexCoord[0].st).rg;

		n = (n-0.5)*2;
		n.g *= -1;

		//rotate normal vector
		n.rg = vec2(n.r * ca + n.g * sa, n.r * sa - n.y * ca);

		float dist = max(0,1-(length(delta)/radius));
		if(dist > 0.01){
			vec2 d = normalize(delta);
			float f = pow((dot(d,n)) * dist * 4 * a,1) *0.33;
			//d = (d + 1) * 0.5;
			gl_FragColor = vec4(r*f,g*f,b*f,1);
		}

	}
}
